﻿using System;
using Xunit;

namespace Unity.String.Tests.Number
{
    public class BufferExtendTest
    {
        [Fact]
        public void ZeroMemoryTest()
        {
            unsafe
            {
                byte[] byteBuffer = { 5, 5, 5, 5, 5 };
                fixed(byte* buffer = byteBuffer) 
                {
                    BufferExtend.ZeroMemory(buffer, (uint) byteBuffer.Length);
                }

                foreach (var value in byteBuffer)
                {
                    Assert.True(value == 0);
                }

                fixed (byte* buffer = byteBuffer)
                {
                    BufferExtend.ZeroMemory(buffer, 0u);
                }
            }
        }

        [Fact]
        public void MemoryCopyTest()
        {
            unsafe
            {
                const int bufferLength = 5;
                byte[] sourceBuffer = {5, 5, 5, 5, 5};
                byte[] destinationBuffer = new byte[bufferLength];
                
                fixed (byte* srcBuffer = sourceBuffer)
                {
                    fixed (byte* destBuffer = destinationBuffer)
                    {
                        BufferExtend.Memcpy(destBuffer, srcBuffer, bufferLength);
                    }
                }

                foreach (var value in sourceBuffer)
                {
                    Assert.True(value == 5);
                }
                
                fixed (byte* srcBuffer = sourceBuffer)
                {
                    fixed (byte* destBuffer = destinationBuffer)
                    {
                        BufferExtend.Memcpy(destBuffer, srcBuffer, 0);
                    }
                }
            }
        }
    }
}